package com.itheima.exam.web;

import com.itheima.exam.constant.AppConstant;
import com.itheima.exam.pojo.entity.User;
import com.itheima.exam.service.UserService;
import com.itheima.exam.web.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping("/login")
    public Result login(HttpSession session, @RequestBody User user){
        User loginUser = userService.login(user);
        //数据脱敏
        loginUser.setPassword("******");
        //保存用户信息
        session.setAttribute(AppConstant.USER_INFO,loginUser);
        return Result.OK(loginUser);
    }

}
